function xOut=sum(xIn,is)
  if(nargin<2)
    is = 1;
  end
  xOut.v = sum(xIn.v,is);
  
  [i,j,x] = find(xIn.d);
  n = size(xIn.v);
  n2 = n;
  n2(is) = 1;
  
  ii = mys2i(n,i);
  ii{is} = ones(size(ii{is}));
  i2 = sub2ind(n2,ii{:});
  xOut.d = sparse(i2,j,x);
  xOut=class(xOut,'deriv1s');

function c = mys2i(size,i)
n = length(size);
c = cell(n,1);
if n==2
  [c{1},c{2}] = ind2sub(size,i);
elseif n==3
  [c{1},c{2},c{3}] = ind2sub(size,i);
elseif n==4
  [c{1},c{2},c{3},c{4}] = ind2sub(size,i);
elseif n==5
  [c{1},c{2},c{3},c{4},c{5}] = ind2sub(size,i);
else
  error('too high dim');
end
  